package heap

func (self *Object) Clone() *Object {
    return &Object{
        class: self.class,
        data:  self.cloneData(),
    }
}

func (self *Object) cloneData() interface{} {
    switch self.data.(type) {
    case []int8:
        elements := self.data.([]int8)
        elements2 := make([]int8, len(elements))
        copy(elements2, elements)
        return elements2
    case []int16:
        elements := self.data.([]int16)
        elements2 := make([]int16, len(elements))
        copy(elements2, elements)
        return elements2
    case []uint16:
        elements := self.data.([]uint16)
        elements2 := make([]uint16, len(elements))
        copy(elements2, elements)
        return elements2
    case []int32:
        elements := self.data.([]int32)
        elements2 := make([]int32, len(elements))
        copy(elements2, elements)
        return elements2
    case []int64:
        elements := self.data.([]int64)
        elements2 := make([]int64, len(elements))
        copy(elements2, elements)
        return elements2
    case []float32:
        elements := self.data.([]float32)
        elements2 := make([]float32, len(elements))
        copy(elements2, elements)
        return elements2
    case []float64:
        elements := self.data.([]float64)
        elements2 := make([]float64, len(elements))
        copy(elements2, elements)
        return elements2
    case []*Object:
        elements := self.data.([]*Object)
        elements2 := make([]*Object, len(elements))
        copy(elements2, elements)
        return elements2
    default: // []Slot
        slots := self.data.(Slots)
        slots2 := newSlots(uint(len(slots)))
        copy(slots2, slots)
        return slots2
    }
}
